package com.csjbot.weedle_auto.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.Button
import android.widget.TextView
import com.csjbot.weedle_auto.R

/**
 * Created by chenqi on 8/7/17.
 */

class ManualAdapter(private val context: Context) : BaseAdapter() {
    private val args = arrayOf("其他检测", "摸手检测", "SN检测")
    override fun getCount(): Int {
        return args.size
    }

    override fun getItem(position: Int): Any {
        return args[position]
    }

    override fun getItemId(position: Int): Long {
        return position.toLong()
    }

    override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
        var v: View
        var viewHolder: ViewHolder
        if (convertView == null) {
            v = LayoutInflater.from(context).inflate(R.layout.list_item, null)
            viewHolder = ViewHolder()
            v.tag = viewHolder
            viewHolder.textView = v.findViewById(R.id.manual_text) as TextView
            viewHolder.button = v.findViewById(R.id.manual_button) as Button
        } else {
            v = convertView
            viewHolder = v.tag as ViewHolder
        }
        for (i in 0 until count) {
            viewHolder.button!!.text = args[i]
        }
        return v
    }

    inner class ViewHolder {
        internal var textView: TextView? = null
        internal var button: Button? = null
    }
}
